﻿using System;
using System.Security.Cryptography;
using System.Text;

namespace Onshi.POS.Modelo.Objetos
{
    public class Encriptacion
    {
        public static String MD5(String cadena)
        {
            var encriptador = new MD5CryptoServiceProvider();
            var data = Encoding.ASCII.GetBytes(cadena);
            data = encriptador.ComputeHash(data);
            var valor = String.Empty;
            for (var i = 0; i < data.Length; i++)
                valor += data[i].ToString("x2").ToLower();
            return valor;
        }

        public static String SHA1(String cadena)
        {
            var encriptador = new SHA1CryptoServiceProvider();
            var data = Encoding.ASCII.GetBytes(cadena);
            data = encriptador.ComputeHash(data);
            var valor = String.Empty;
            for (var i = 0; i < data.Length; i++)
                valor += data[i].ToString("x2").ToLower();
            return valor;
        }

        public static String SHA256(String cadena)
        {
            var encriptador = new SHA256CryptoServiceProvider();
            var data = Encoding.ASCII.GetBytes(cadena);
            data = encriptador.ComputeHash(data);
            var valor = String.Empty;
            for (var i = 0; i < data.Length; i++)
                valor += data[i].ToString("x2").ToLower();
            return valor;
        }
    }
}
